<?php defined('IN_KG') or exit('Access Invalid!');?>

<link rel="stylesheet" href="/data/resource/layui/layui.all.js">
<link rel="stylesheet" href="/data/resource/layui/css/layui.css">
<style>
    .alter{
         float: right;
         margin-right: 10px;
         width: 50px;
         height: 28px;
         background-color: #36BC9B;
         border: 0px;
         color: white;
     }

    .rec{
        float: right;
        margin-right: 10px;
        width: 50px;
        height: 28px;
        background-color: white;
        border: 0;
        color: black;
        font-size: 0.7px;
        text-decoration: inherit;

    }

    .rec:hover {color: red; text-decoration:underline;}
</style>
<div class="tabmenu">
  <?php include template('layout/submenu');?>
<?php if ($output['isOwnShop']) { ?>
  <!--<a href="<?php /*echo urlShop('store_groupbuy', 'groupbuy_add_vr'); */?>" style="right:100px" class="ncbtn ncbtn-mint" title="新增虚拟商品团购"><i class="icon-plus-sign"></i>新增虚拟团购</a>-->
  <a href="<?php echo urlShop('store_groupbuy', 'groupbuy_add');?>" class="ncbtn ncbtn-mint" title="<?php echo $lang['groupbuy_index_new_group'];?>"><i class="icon-plus-sign"></i><?php echo $lang['groupbuy_index_new_group'];?></a>
<?php } else { ?>

  <?php if(!empty($output['current_groupbuy_quota'])) { ?>
  <a href="<?php echo urlShop('store_groupbuy', 'groupbuy_add_vr'); ?>" style="right:200px" class="ncbtn ncbtn-mint" title="新增虚拟商品团购"><i class="icon-plus-sign"></i>新增虚拟团购</a>
  <a href="<?php echo urlShop('store_groupbuy', 'groupbuy_add');?>" style="right:100px" class="ncbtn ncbtn-mint" title="<?php echo $lang['groupbuy_index_new_group'];?>"><i class="icon-plus-sign"></i><?php echo $lang['groupbuy_index_new_group'];?></a>
  <a class="ncbtn ncbtn-aqua" href="<?php echo urlShop('store_groupbuy', 'groupbuy_quota_add');?>" title="套餐续费"><i class="icon-money"></i>套餐续费</a>
  <?php } else { ?>
  <a class="ncbtn ncbtn-aqua" href="<?php echo urlShop('store_groupbuy', 'groupbuy_quota_add');?>" title="购买套餐"><i class="icon-money"></i>购买套餐</a>
  <?php } ?>
<?php } ?>

</div>
<?php if ($output['isOwnShop']) { ?>
<div class="alert alert-block mt10">
  <ul class="mt5">
    <li>1、点击新增团购按钮可以添加团购活动</li>
    <li>2、如发布虚拟商品的团购活动，请点击新增虚拟团购按钮</li>
  </ul>
</div>
<?php } else { ?>
<div class="alert alert-block mt10">
  <?php if(!empty($output['current_groupbuy_quota'])) { ?>
  <strong>套餐过期时间<?php echo $lang['nc_colon'];?></strong><strong style="color: #F00;"><?php echo date('Y-m-d H:i:s', $output['current_groupbuy_quota']['end_time']);?></strong>
  <?php } else { ?>
  <strong>当前没有可用套餐，请先购买套餐</strong>
  <?php } ?>
  <ul class="mt5">
    <li>1、点击购买套餐和套餐续费按钮可以购买或续费套餐</li>
    <li>2、点击新增团购按钮可以添加团购活动</li>
    <li>3、如发布虚拟商品的团购活动，请点击新增虚拟团购按钮</li>
    <li>4、<strong style="color: red">相关费用会在店铺的账期结算中扣除</strong></li>
  </ul>
</div>
<?php } ?>

<table class="search-form">
  <form method="get">
    <input type="hidden" name="control" value="store_groupbuy" />
    <tr>
      <td>&nbsp;</td>
      <th>团购类型</th>
      <td class="w100">
        <select name="groupbuy_vr" class="w90">
          <option value="">全部</option>
          <option value="0"<?php if ($output['groupbuy_vr'] === '0') echo ' selected'; ?>>线上抢</option>
          <option value="1"<?php if ($output['groupbuy_vr'] === '1') echo ' selected'; ?>>虚拟团</option>
        </select>
      </td>
      <th><?php echo $lang['groupbuy_index_activity_state'];?></th>
      <td class="w100"><select name="groupbuy_state" class="w90">
          <?php if(is_array($output['groupbuy_state_array'])) { ?>
          <?php foreach($output['groupbuy_state_array'] as $key=>$val) { ?>
          <option value="<?php echo $key;?>" <?php if($key == $_GET['groupbuy_state']) { echo 'selected';}?>><?php echo $val;?></option>
          <?php } ?>
          <?php } ?>
        </select></td>
      <th><?php echo $lang['group_name'];?></th>
      <td class="w160"><input class="text" type="text" name="groupbuy_name" value="<?php echo $_GET['groupbuy_name'];?>"/></td>
      <td class="w70 tc"><label class="submit-border"><input type="submit" class="submit" value="<?php echo $lang['nc_search'];?>" /></label></td>
    </tr>
  </form>
</table>
<table class="ncsc-default-table">
  <thead>
    <tr>
      <th class="w50"></th>
      <th class="tl"><?php echo $lang['group_name'];?></th>
      <th class="w130">开始时间</th>
      <th class="w130">结束时间</th>
      <th class="w90">浏览数</th>
      <th class="w90">已参与人数</th>
      <th>活动推荐</th>
      <th>增加参与人数</th>
      <th class="w110"><?php echo $lang['groupbuy_index_activity_state'];?></th>


    </tr>
  </thead>
  <tbody>
    <?php if(!empty($output['group']) && is_array($output['group'])){?>
    <?php foreach($output['group'] as $key=>$group){?>
    <tr class="bd-line">
      <td></td>
      <!--<td><div class="pic-thumb"><a href="/index.php?control=store_groupbuy&op=gruopbuy_info&group_id=<?php /*echo $group['groupbuy_id']*/?>"><img src="<?php /*echo gthumb($group['groupbuy_image'], 'small');*/?>"/></a></div></td>-->

      <td class="tl">
        <dl class="goods-name">
          <dt>
<?php if ($group['is_vr']) { ?>
            <span title="虚拟兑换商品" class="type-virtual">虚拟团</span>
<?php } ?>
            <a href="/index.php?control=store_groupbuy&op=gruopbuy_info&group_id=<?php echo $group['groupbuy_id']?>"><?php echo $group['groupbuy_name'];?></a>
          </dt>
        </dl>
      </td>
      <td><?php echo $group['start_time_text'];?></td>
      <td><?php echo $group['end_time_text'];?></td>
      <td><?php echo $group['views'];?></td>
      <td><?php echo $group['buyer_count'];?></td>

        <td>
        <?php if ($group['state'] == 20){?>
            <?php if ($group['recommended'] == 0){?>
                <input type="button" onclick="recommend(<?php echo $group['groupbuy_id'];?>,1)" value="首页推荐" class="rec">
            <?php }else{?>
                <input type="button" onclick="recommend(<?php echo $group['groupbuy_id'];?>,0)" value="取消推荐" class="rec">
            <?php }?>
        <?php }else{?>
            <input type="button" onclick="recommend(<?php echo $group['groupbuy_id'];?>,0)" class="rec">
        <?php }?>
        </td>

      <?php if ($group['state'] == 20){?>
          <td style="text-align: center;width: 150px;">
              <input type="text" id="number_<?php echo $group['groupbuy_id'];?>" style="width: 50px;float: left;text-align: center;margin-left: 20px;">
              <input type="button" value="增加" style="float: right;margin-right: 10px;" class="alter" onclick="alterPerson(<?php echo $group['groupbuy_id'];?>)">
          </td>
      <?php }else{?>
          <td>
              &nbsp;&nbsp;&nbsp;
          </td>
      <?php }?>

        <td><?php echo $group['groupbuy_state_text'];?></td>
    </tr>
    <?php }?>
    <?php }else{?>
    <tr>
      <td colspan="20" class="norecord"><div class="warning-option"><i class="icon-warning-sign"></i><span><?php echo $lang['no_record'];?></span></div></td>
    </tr>
    <?php }?>
  </tbody>
  <tfoot>
    <tr>
      <td colspan="20"><div class="pagination"><?php echo $output['show_page']; ?></div></td>
    </tr>
  </tfoot>
</table>

<script>
    function alterPerson(groupbuy_id){
        var number = $("#number_"+ groupbuy_id).val();

        $.post("index.php?control=store_groupbuy&op=groupbuy_add_buyer_count",{'number':number,'groupbuy_id':groupbuy_id},function(result){
            result = JSON.parse(result);

            if(result.code == 200){
                alert(result.msg);
                window.location.reload();
            }else{
                alert(result.msg);
            }
        });
    }

    function recommend(groupbuy_id,recommon_status){
        $.post("index.php?control=store_groupbuy&op=groupbuy_recommon",{'recommon_status':recommon_status,'groupbuy_id':groupbuy_id},function(result){
            console.log(result);
            result = JSON.parse(result);
            if(result.code == 200){
                alert(result.msg);
                window.location.reload();
            }else{
                alert(result.msg);
            }
        });
    }
</script>
